<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
	//指定根路径  127.0.0.1：8080/crm
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/";
%>
<html>
<head>
	<base href=<%=basePath%>>
	<meta charset="UTF-8">
	<link href="jquery/bootstrap_3.3.0/css/bootstrap.min.css" type="text/css" rel="stylesheet" />
	<script type="text/javascript" src="jquery/jquery-1.11.1-min.js"></script>
	<script type="text/javascript" src="jquery/bootstrap_3.3.0/js/bootstrap.min.js"></script>

	<script type="text/javascript">
		if(window.top!=window){
			window.top.location=window.location;
		}

		$(function () {
			$("#userAct").val("");
			$("#userPsw").val("");

			$("#userAct").focus();

			$("#btn").click(function () {
				//点击事件
				if(loginListDev()){
					login();
				}
			})

			$(window).keydown(function (event) {
				//点回车
				if(event.keyCode == 13){
					if(loginListDev()){
						login();
					}
				}
			})

		})

		//表单验证  返回true or false
		loginListDev = function () {
			let act = $("#userAct").val();
			let psw = $("#userPsw").val();

			if(act == "" || psw == ""){
				$("#msg").html("账号密码不可为空！")
				return false;
			}
			else{
				$("#msg").html("")
				return true;
			}
		}

		//异步请求  发送登录请求
		login = function () {
			let act = $.trim($("#userAct").val());
			let psw = $.trim($("#userPsw").val());

			$.ajax({
				url : "settings/user/login.do",
				data : {
					"userAct" : act,
					"userPsw" : psw
				},
				type : "post",
				dataType : "json",
				success : function (data) {
					// data = {json:123}

					if(data.success){
						window.location.href = "workbench/index.jsp";
					}
					else{
						$("#msg").html(data.msg);
					}
				}
			})
		}

	</script>

</head>
<body>
	<div style="position: absolute; top:5%; left: 0px; width: 100% ; height: 95%">
		<img src="image/cover.jpg" style="width: 100%; height: 100%; position: relative; top: 0px;">
	</div>

	<div id="top" style="height: 50px;top:0px; left: 0px; background-color:black; width: 100%;">
		<div style="position: absolute; top: 5px; left: 0px; font-size: 30px; font-weight: 400; color: white; font-family: 'times new roman'">
			CRM-Webapp &nbsp;
			<span style="font-size: 12px;">made by ConghuCai</span>
		</div>
	</div>
	
	<div style="background-color: white; position: absolute; top: 230px; right: 300px;width:450px;height:400px;border:1px solid black">
		<div style="position: absolute; top: 0px; right: 60px;">
			<div class="page-header">
				<h1>登录</h1>
			</div>
			<form class="form-horizontal" role="form">
				<div class="form-group form-group-lg">
					<div style="width: 350px;">
						<input class="form-control" type="text" placeholder="用户名" id="userAct">
					</div>
					<div style="width: 350px; position: relative;top: 20px;">
						<input class="form-control" type="password" placeholder="密码" id="userPsw">
					</div>
					<div class="checkbox"  style="position: relative;top: 30px; left: 10px;">
						
						<span id="msg"></span>
						
					</div>
					<button type="button" id="btn" class="btn btn-primary btn-lg btn-block"  style="width: 350px; position: relative;top: 45px;">登录</button>
				</div>
			</form>
		</div>
	</div>
</body>
</html>